package com.alibaba.algo.controller.user;

import com.alibaba.algo.annotation.OperateLogAnnotation;
import com.alibaba.algo.apiimpl.user.SysEmployeeGroupServiceImpl;
import com.alibaba.algo.cooperation.common.BaseResult;
import com.alibaba.algo.cooperation.usercenter.GlobalResultStatus;
import com.alibaba.algo.cooperation.usercomponent.vo.req.user.SysEmployeeGroupDeleteRequestVO;
import com.alibaba.algo.cooperation.usercomponent.vo.req.user.SysEmployeeGroupPageRequestVO;
import com.alibaba.algo.enums.OperateTypeEnum;
import com.alibaba.algo.enums.ResourceTypeEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author Fan.tianpeng
 * @date 2021/5/7 19:43
 */
@RestController
@RequestMapping(value = "/usercenter-admin-app/admin/sysEmployeeGroup")
public class SysEmployeeGroupController {

    @Autowired
    private SysEmployeeGroupServiceImpl sysEmployeeGroupService;

    @PostMapping("/selectPage")
    public BaseResult selectEmployeeGroupPage(@RequestBody SysEmployeeGroupPageRequestVO vo) {
        if (ObjectUtils.isEmpty(vo.getPageIndex())) {
            return BaseResult.buildError(GlobalResultStatus.PARAM_PAGE_INDEX_ERROR.getCode(), GlobalResultStatus.PARAM_PAGE_INDEX_ERROR.getMsg());
        }
        if (ObjectUtils.isEmpty(vo.getPageSize())) {
            return BaseResult.buildError(GlobalResultStatus.PARAM_PAGE_SIZE_ERROR.getCode(), GlobalResultStatus.PARAM_PAGE_SIZE_ERROR.getMsg());
        }
        return sysEmployeeGroupService.selectEmployeeGroupPage(vo);
    }

    @PostMapping(value = "delete")
    @OperateLogAnnotation(resouceType = ResourceTypeEnum.GROUP,operateType = OperateTypeEnum.DELETE)
    BaseResult singleDelete(@RequestBody SysEmployeeGroupDeleteRequestVO vo) {
        return sysEmployeeGroupService.singleDelete(vo);
    }
}
